@extends('admin.layout.base')

@section('content')
    <div class="layui-form-item">
        <div class="layui-inline">
            <input class="layui-input search-data" name="name" placeholder="账户名" autocomplete="off">
        </div>

        <div class="layui-inline">
            <input class="layui-input search-data" name="phone" placeholder="手机号" autocomplete="off">
        </div>

        <div class="layui-inline layui-form">
            <select name="status" class="search-data">
                <option value="">状态</option>
                <option value="0">启用</option>
                <option value="1">停用</option>
            </select>
        </div>

        <div class="layui-inline layui-form">
            <select name="roles" class="search-data">
                <option value="">角色</option>
                @foreach($data as $item)
                    <option value="{{$item['id']}}">{{$item['display']}}</option>
                @endforeach
            </select>
        </div>

        {{--<div class="layui-inline layui-form">
            <div class="layui-input-block" id="roles" data-roles="{{$roles}}" style="margin-left:0px;min-height:32px;"></div>
        </div>--}}

        <div class="layui-inline demoTable">
            <button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin" data-type="search" lay-filter="search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>

            @can('admin.create')
            <button data-url="{{route("admin.create")}}" data-type="openViews" class="layui-btn layui-btn-sm">添 加</button>
            @endcan
        </div>
    </div>

    <div class="layui-card">

        <table class="layui-hide" id="tableData" lay-filter="myTable"></table>

        <script type="text/html" id="status">
            <a lay-event="status">
                @{{# if(d.id != 1){ }}
                <input type="checkbox" data-url="{{route("admin.status")}}" data-id="switch_@{{d.id}}" value="@{{d.status}}" @{{d.status==0?'checked':''}} lay-skin="switch" lay-text="启用|停用">
                @{{#  }else{ }}
                <input type="checkbox" @{{d.status==0?'checked':''}} disabled lay-skin="switch" lay-text="启用|停用">
                @{{#  } }}
            </a>
        </script>

        <script type="text/html" id="options">
            <div class="layui-btn-group">
                @can('admin.edit')
                <a data-url="{{route("admin.edit")}}" lay-event="edit" class="layui-btn layui-btn-xs layui-btn-normal">编辑</a>
                @endcan
                @can('admin.delete')
                @{{# if(d.id != 1){ }}
                <a data-url="{{route("admin.delete")}}" lay-event="del" class="layui-btn layui-btn-xs layui-btn-danger">删除</a>
                @{{#  } }}
                @endcan
            </div>
        </script>

    </div>

@endsection

@section('script')
    <script>
        layui.use(['table', 'layer', 'jquery', 'selectM'], function () {
            $ = layui.jquery;
            var table = layui.table;
            var selectM = layui.selectM;
            table.render({
                elem: '#tableData'
                , url: '{{route("admin.list")}}'
                , cols: [[
                    {field: 'id', title: 'ID', sort: true, width: 60}
                    , {field: 'name', title: '账户名', sort: true, width: 120}
                    , {field: 'admin_roles', title: '角色',minWidth:150}
                    , {field: 'phone', title: '手机号', width: 120}
                    , {field: 'email', title: '邮箱', width: 150}
                    , {field: 'created_at', title: '创建时间', width: 160}
                    , {field: 'status',fixed: 'right', title: '状态', toolbar: '#status', width: 100}
                    , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#options'}
                ]]
                , id: 'myReload'
                , page: true
                /*,limits: [ 2, 5, 30, 50]
                ,limit:2*/
            });

            /*selectM({
                elem: '#roles'//元素容器【必填】
                , data: $('#roles').data('roles')//候选数据【必填】
                , name: 'roles'
                , width: 350
            });

            //多选框样式
            $('.lay-ext-mulitsel .tips').css('top', '8px');
            $('.layui-form-select dl dd').css('margin-bottom', '5px');
            //设置多选框属性
            var roleObj = $('input[name="roles"]');
            roleObj.attr('class', 'layui-input layui-unselect search-data');
            */
        });
    </script>
@endsection